package cn.edu.jxau.controller;

import cn.edu.jxau.bean.Customer;
import cn.edu.jxau.core.annotation.Action;
import cn.edu.jxau.core.annotation.Controller;
import cn.edu.jxau.core.annotation.Inject;
import cn.edu.jxau.core.util.UploadUtils;
import cn.edu.jxau.core.web.Data;
import cn.edu.jxau.core.web.FileFieldParam;
import cn.edu.jxau.core.web.Param;
import cn.edu.jxau.core.web.View;
import cn.edu.jxau.service.CustomerService;

import java.io.IOException;
import java.util.List;

/**
 * Desc:
 * ------------------------------------
 * Author:fulei04@meituan.com
 * Date:2017/12/15
 * Time:下午2:23
 */
@Controller
public class CoreController {

    @Inject
    private CustomerService service;

    @Action("get:/")
    public View index() {
        return new View("index.jsp");
    }

    @Action("get:/customer")
    public Data getCustomer(Param param) {

        Customer customer = new Customer();
        customer.setId(1);
        customer.setContact("Fudashi");
        customer.setEmail("fudashi233@aliyun.com");
        customer.setName("Fudashi");
        customer.setTelephone("15083825093");
        customer.setRemark("Don't be shy");
        return new Data(customer);
    }

    @Action("post:/upload")
    public View upload(Param param) {

        try {
            List<FileFieldParam> fileFieldParam = param.getFileFieldParamList("picture");
            UploadUtils.upload("/Users/fudashi/Desktop/upload",fileFieldParam);
            return new View("index.jsp");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
